package pers.liu.yibandemo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import pers.liu.yibandemo.entity.ChatLog;
import pers.liu.yibandemo.service.ChatLogService;

import java.util.List;

@RestController
@RequestMapping("/chatlogs")
public class ChatLogController {

    @Autowired
    private ChatLogService chatLogService;

    @PostMapping("/add")
    public ResponseEntity<String> addChatLog(@RequestBody ChatLog chatLog) {
        chatLogService.addChatLog(chatLog);
        return ResponseEntity.ok("Chat log added successfully.");
    }

    @GetMapping("/all")
    public ResponseEntity<List<ChatLog>> getAllChatLogs() {
        List<ChatLog> chatLogs = chatLogService.getAllChatLogs();
        return ResponseEntity.ok(chatLogs);
    }

    @GetMapping("/{userId}")
    public ResponseEntity<List<ChatLog>> getUserChatLogs(@PathVariable Integer userId) {
        List<ChatLog> chatLogs = chatLogService.getChatLogs(String.valueOf(userId));
        return ResponseEntity.ok(chatLogs);
    }
}
